﻿<%@ Page Title="Rule Defination" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="RuleDefinition.aspx.cs" Inherits="RuleDefinition" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:Label ID="lableTitle" runat="server" Text="Rule Definition" Font-Bold="true"
        Font-Size="Medium" ForeColor="Black"></asp:Label>
    <table style="width: 100%;" border="1px">
        <tr>
            <td rowspan="4" style="width: 20%;" align="left" valign="top">
                <asp:ListBox ID="LBRule" runat="server" Width="100%" OnSelectedIndexChanged="LBRule_SelectedIndexChanged"
                    Rows="25" DataSourceID="SDSRulesList" DataTextField="Name" DataValueField="RowNo"
                    AutoPostBack="True" Height="459px"></asp:ListBox>
                <asp:SqlDataSource ID="SDSRulesList" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                    SelectCommand="SELECT [RowNo], [Name] FROM [RuleDetails] ORDER BY [Name]"></asp:SqlDataSource>
            </td>
        </tr>
        <tr>
            <td align="left" valign="top" style="height: 100px;">
                <asp:Panel runat="server" ID="PanelUpper">
                    <br />
                    <asp:Label ID="LabelName" runat="server" Text="Rule Name" Width="100px"></asp:Label>
                    <asp:TextBox ID="TBRuleName" runat="server" Width="400px" OnTextChanged="TBRuleName_TextChanged"
                        AutoPostBack="True"></asp:TextBox>
                    <br />
                    <br />
                    <asp:Label ID="LabelFromDate" runat="server" Text="From Date :" Width="100px"></asp:Label>
                    <asp:TextBox ID="TBFromDate" runat="server" Width="150px" OnTextChanged="TBFromDate_TextChanged"
                        AutoPostBack="True"></asp:TextBox>
                    <ajax:CalendarExtender ID="CalendarFromDate" runat="server" PopupButtonID="TBFromDate"
                        TargetControlID="TBFromDate" Format="yyyy-MM-dd">
                    </ajax:CalendarExtender>
                    &nbsp;&nbsp;&nbsp;<asp:Label ID="LabelToDate" runat="server" Text="To Date :" Width="80px"></asp:Label>
                    <asp:TextBox ID="TBToDate" runat="server" Width="150px" OnTextChanged="TBToDate_TextChanged"
                        AutoPostBack="True"></asp:TextBox>
                    <ajax:CalendarExtender ID="CalendarToDate" runat="server" PopupButtonID="TBToDate"
                        TargetControlID="TBToDate" Format="yyyy-MM-dd">
                    </ajax:CalendarExtender>
                    <br />
                    <br />
                    <asp:Label ID="LabelRepeat" runat="server" Text="Frequency" Width="100px"></asp:Label>
                    <asp:CheckBox ID="CBRepeats" runat="server" AutoPostBack="True" OnCheckedChanged="CBRepeats_CheckedChanged"
                        Text=" Repeat" Width="100px" />
                    <asp:Label ID="LabelEvery" runat="server" Text="Every"></asp:Label>
                    &nbsp;<asp:DropDownList ID="DDLFrequency" runat="server" OnLoad="DDLFrequency_Load">
                    </asp:DropDownList>
                    &nbsp;&nbsp;&nbsp;
                    <asp:DropDownList ID="DDLFreqType" runat="server">
                        <asp:ListItem Selected="True">Days</asp:ListItem>
                        <asp:ListItem>Weeks</asp:ListItem>
                        <asp:ListItem>Month</asp:ListItem>
                        <asp:ListItem>Year</asp:ListItem>
                    </asp:DropDownList>
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Panel runat="server" ID="PanelMiddle" Enabled="False">
                    <table style="width: 100%; height: 100%;">
                        <tr>
                            <td style="width: 40%;">
                                <asp:Label ID="LabelAll" runat="server" Text="All SubRules" Width="150px"></asp:Label>
                                <br />
                                <asp:ListBox ID="LBAllRules" runat="server" Rows="15" Width="100%" DataSourceID="SDSAll"
                                    DataTextField="Name" DataValueField="RowNo" Enabled="False"></asp:ListBox>
                                <asp:SqlDataSource ID="SDSAll" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                                    SelectCommand="SELECT [RowNo], [Name] FROM [Formula] WHERE ( [Type] = 'SubRule' ) AND ( [RowNo] NOT IN ( SELECT [SubRuleId] from [RuleRelations] where [RuleId] = @RuleId ) ) ORDER BY [Name]">
                                    <SelectParameters>
                                        <asp:ControlParameter ControlID="LBRule" Name="RuleId" PropertyName="SelectedValue" DefaultValue="-1" />
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </td>
                            <td style="width: 10%;" align="center" valign="middle">
                                <asp:ImageButton ID="IBRight" runat="server" BorderStyle="Solid" Height="20px" ImageUrl="~/_images/arrow-right.jpg"
                                    Width="20px" OnClick="IBRight_Click" />
                                <br />
                                <br />
                                <asp:ImageButton ID="IBLeft" runat="server" BorderStyle="Solid" Height="20px" ImageUrl="~/_images/arrow-left.jpg"
                                    Width="20px" OnClick="IBLeft_Click" />
                            </td>
                            <td style="width: 40%;">
                                <asp:Label ID="LabelSelected" runat="server" Text="Selected SubRules" Width="150px"></asp:Label>
                                <br />
                                <asp:ListBox ID="LBSelected" runat="server" Width="100%" Rows="15" DataSourceID="SDSSelected"
                                    DataTextField="Name" DataValueField="SubRuleID"></asp:ListBox>
                                <asp:SqlDataSource ID="SDSSelected" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
                                    SelectCommand="select r.SubRuleID, f.Name from RuleRelations r, Formula f WHERE r.SubRuleID = f.RowNo AND r.RuleId = @RuleId ORDER BY r.Priority">
                                    <SelectParameters>
                                        <asp:ControlParameter ControlID="LBRule" Name="RuleId" PropertyName="SelectedValue" />
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </td>
                            <td style="width: 40%;" align="center" valign="middle">
                                <asp:ImageButton ID="IBUp" runat="server" BorderStyle="Solid" Height="20px" ImageUrl="~/_images/arrow-up.jpg"
                                    Width="20px" OnClick="IBUp_Click" />
                                <br />
                                <br />
                                <asp:ImageButton ID="IBDown" runat="server" BorderStyle="Solid" Height="20px" ImageUrl="~/_images/arrow-down.jpg"
                                    Width="20px" OnClick="IBDown_Click" />
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td align="center" valign="middle">
                <asp:Button ID="BApply" runat="server" Text="Apply" Width="100px" OnClick="BApply_Click" />
                <asp:Button ID="BCreate" runat="server" Text="Create New" Width="100px" OnClick="BCreate_Click" />
                &nbsp;<asp:Button ID="BCancel" runat="server" Text="Cancel" Width="100px" OnClick="BCancel_Click" />
                <asp:Button ID="BEdit" runat="server" Text="Edit" Width="100px" OnClick="BEdit_Click" />
            </td>
        </tr>
    </table>
</asp:Content>
